package sniff.diller;

import jpcap.packet.IPPacket;
import jpcap.packet.Packet;
import sniff.pack.CommonIPChildPacket;
import sniff.pack.CommonIPPacket;
import sniff.pack.MyIPv4Packet;
import util.ByteUtil;

public class IPPackageDillDispatcher {

	public static CommonIPPacket dispatchAndGetAfterDill(Packet pack) {
		CommonIPChildPacket childPack = null;
		CommonIPPacket comPack=null;
		IPPacket ipPack = (IPPacket)pack;
		int protocolCode = ByteUtil.byteToInt(pack.header[23]);
		switch (protocolCode) {
		case 1:// ICMP
			childPack = ICMPPacketDiller.dill(pack);
			break;
		case 2:// IGMP
//			childPack = IPv4PacketCommonDiller.dill(pack);
			break;
		case 6:// TCP
			childPack = TCPPacketDiller.dill(pack);
			break;
		case 8:// EGP
//			childPack = IPv4PacketCommonDiller.dill(pack);
			break;
		case 9:// IGP
//			childPack = IPv4PacketCommonDiller.dill(pack);
			break;
		case 17:// UDP
			childPack = UDPPacketDiller.dill(pack);
			break;
		case 41:// IPv6
//			childPack = IPv4PacketCommonDiller.dill(pack);
			break;
		case 50:// ESP
//			childPack = IPv4PacketCommonDiller.dill(pack);
			break;
		case 89:// OSPF
			childPack = OSPFPacketDiller.dill(pack);
			break;
		default:
			break;
		}
		if(ipPack.version==4) {
			comPack = IPv4PacketDiller.dill(pack);
			((MyIPv4Packet)comPack).setChildPacket(childPack);
		}else if(ipPack.version==6) {
			comPack =IPv6PacketDiller.dill(pack);
		}
		return comPack;
	}

}
